/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.commands.user;

import com.bionic.commands.common.ICommand;
import com.bionic.dao.UserDAO;
import com.bionic.entity.Users;
import com.bionic.manager.Config;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Obuhov D.G.
 */
public class CUserUpdate implements ICommand {

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null;
        HttpSession session = request.getSession(true);
        Users user = (Users)session.getAttribute("currentUser");
        if ((user!=null)&&(user.getId() != null)) {
            UserDAO userDAO = new UserDAO();    
            user = userDAO.findById(user.getId());
             if (user != null) {
                request.setAttribute("userBean", user);
                page = Config.getInstance().getProperty(Config.USER_EDIT);
            } else {
                page = Config.getInstance().getProperty(Config.ERROR);
            }
        } else {
            page = Config.getInstance().getProperty(Config.LOGIN);
        }   
   
        return page;
    }
}
